package pers.richard.example.dao;

import java.util.List;
import java.util.Map;

import pers.richard.example.dto.QueryDto;
import pers.richard.example.dto.UserDto;
import pers.richard.example.po.User;
import pers.richard.example.po.User.Field;
import pers.richard.ormybatis.annotation.DaoConfig;
import pers.richard.ormybatis.annotation.SelectId;
import pers.richard.ormybatis.annotation.SelectParamName;
import pers.richard.ormybatis.bean.sql.Where;
import pers.richard.ormybatis.dao.OrmybatisBaseDao;

@DaoConfig(table = "user", id = "user_id")
public class UserDao extends OrmybatisBaseDao<User> {

	@SelectId
	public UserDto getNameAndAgeById(QueryDto dto , int age) {return null;}
	
	@SelectParamName
	public Map byUserIdAndName(Integer userId, String name) {return null;}

	public List<User> byName() {
		Where w = Where.create().eq(Field.NAME, "").eq(Field.AGE, null);
		return super.selectList(w);
	}

	public List<Integer> getAgeByAll() {
		return super.selectListByField(Field.USER_ID, Where.create(Field.USER_ID, 0));
	}

	public User findOneByMap(Map paramMap) {
		return super.selectOne(paramMap);
	}

	public int countByMap(Map paramMap) {
		return super.count(paramMap);
	}

	public void update() {
		User u = new User();
		u.setUserId(1);
		u.setName("update hos name");
		int num = super.update(u);
		log.debug("修改记录数 :{}", num);
	}

	public int insertOrUpdate() {
		User u = new User();
		u.setUserId(10);
		u.setAge(100);
		int num = super.insertOrUpdate(u);
		return num;
	}

	public int saveOrUpdateByName(User user) {
		Where where = Where.create().like(Field.NAME, user.getName());
		return super.insertOrUpdate(user, where);
	}

	public int deleteByBuilder() {
		Where where = Where.create().like(Field.NAME, "name");
		int num = super.delete(where);
		return num;
	}

	public int updateUser(User u) {
		return super.update(u);
	}
}